<?

namespace Database\Mysql;

class ResultObject {

    private $result = false;
    private $sql = false;

    public function __construct($resourse, $sql) {
        $this->result = $resourse;
        $this->sql = $sql;
        return $this;
    }

    public function fetchObj($class_name = null) {
        if (!$this->result) {
            return false;
        }
        if ($class_name) {
            return mysql_fetch_object($this->result, $class_name);
        } else {
            return mysql_fetch_object($this->result);
        }
    }

    public function fetchArray($type = MYSQL_BOTH) {
        if (!$this->result) {
            return false;
        }
        return mysql_fetch_array($this->result, $type);
    }

    public function fetch() {
        if (!$this->result) {
            return false;
        }
        return mysql_fetch_assoc($this->result);
    }

    public function getList($type = "fetch", $add = false) {
        if (!$this->result) {
            return false;
        }
        $func = $type;
        $data = array();
        if ($add) {
            while ($el = self::$func($add)) {
                $data[] = $el;
            }
        } else {
            while ($el = self::$func()) {
                $data[] = $el;
            }
        }
        return $data;
    }

    function getObj() {
        return $this->result;
    }

    function isTrue() {
        return $this->result == true;
    }
    
    function Sql() {
        return $this->sql;
    }

}
